var prefix = ctx + "admin/role";

function setPerm(roleId) {
    var url = prefix + '/goSetPerm/' + roleId;
    $.modal.open("分配权限", url);
}

$(function() {
    var options = {
        url: prefix + "/page",
        updateUrl: prefix + "/goEditRole",
        removeUrl: prefix + "/{id}",
        exportUrl: prefix + "/export",
        sortName: "roleName",
        sortOrder: "asc",
        modalName: "角色",
        columns: [{
                title: "序号",
                formatter: function (value, row, index) {
             	    return $.table.serialNumber(index);
                }
            }, 
            {
    	    field: 'roleName',
    	    title: '角色名称',
    	    sortable: true,
    	    formatter: function (value, row, index) {
    	    	return '<a href="javascript:$.operate.view(' + "'" + row.roleId + "'" + ')">' + value + '</a>';
    	    },
    	},
    	{
    	    field: 'roleCode',
    	    title: '角色编码',
    	    sortable: true
    	},{
    	    field: 'dsType',
    	    title: '数据权限类型',
    	    formatter: function (value, row, index) {
    	    	if('0'==value){
    	    		return '全部';
    	    	}
    	    	if('2'==value){
    	    		return '本级及子级';
    	    	}
    	    	if('3'==value){
    	    		return '本级';
    	    	}
    	    	if('1'==value){
    	    		return '自定义';
    	    	}
            }
    	},{
			field : 'createTime',
			title : '创建时间',
			sortable : true
		},{
            title: '操作',
            formatter: function (value, row, index) {
                var actions = [];
                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.roleId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                actions.push('<a class="btn btn-danger btn-xs ' + deleteFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.roleId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                actions.push('<a class="btn btn-info btn-xs ' + permFlag + '" href="javascript:void(0)" onclick="setPerm(\'' + row.roleId + '\')"><i class="fa fa-user"></i>分配权限</a> ');
                return actions.join('');
            }
        }]
    };
    $.table.init(options);
});